<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->Increments('id')->comment('自增id');
			$table->string('user_name',32)->comment('用户名')->unique();
			$table->string('passwd',32)->default(md5("123456".env('PASSWD_SALT', 'finalove')))->comment('用户密码');
			$table->string('real_name',32)->default(0)->comment('真实姓名')->index();
			$table->string('phone',32)->default(0)->comment('电话号码')->index();
			$table->string('email',32)->default(0)->comment('邮箱')->index();
			$table->string('head',255)->default("/images/head_404.jpg")->comment('头像');
			$table->Integer('role_id')->default(0)->unsigned()->comment('角色id')->index();
			$table->Integer('depart_id')->default(0)->unsigned()->comment('部门id')->index();
			$table->enum('status',[0=>"禁用",1=>"正常"])->default("正常")->comment('账号状态');
			$table->enum('data_auth_type',[
				0=>"仅自己",1=>"所有",2=>"本部门",3=>"本部门及子部门"
			])->default("仅自己")->comment('数据权限类型');
			$table->Integer('login_times')->default(0)->unsigned()->comment('登录次数');
			$table->ipAddress('last_login_ip')->default(0)->comment('最后登录ip');
			$table->dateTime('last_login_time')->nullable()->comment('最后登录时间');
			$table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
